<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<script type="text/javascript">
		/*一般创建对象*/
			var obj={
				name:"张",
				age:1,
				gender:"男",
				sayName:function(){
					alert(this.name);
				}
			};
			console.log(obj);
		/*工厂方法创建对象（不常用)*/
			function createPerson(name,age,gender){
				var obj=new Object();
				obj.name=name;
				obj.age=age;
				obj.gender=gender;
				obj.sayName=function(){
					alert(this.name);
				};
				return obj;
			}
			var obj1=createPerson("张三",13,"男");
			var obj2=createPerson("李四",14,"女");
			console.log(obj1);
			console.log(obj2);
		/*构造函数创建对象Person*/
			function Person(name,age,gender){
				this.name=name;
				this.age=age;
				this.gender=gender;
				this.sayName=function(){
					console.log(this.name);
				}
			}
			var per1=new Person("菜三",18,"男");
			var per2=new Person("菜问",19,"男");
			per1.sayName();
			console.log(per1);
			console.log(per2);
		/*构造函数创建对象Dog*/
			function Dog(name,age){
				this.name=name;
				this.age=age;
				this.sayName=function(){
					console.log(this.name);
				}
			}
			var dog=new Dog("吉吉",3);
			console.log(dog);
		/*构造函数执行多少次就创建多少次sayName，这是没有必要的，可以改成（1）*/
			function Dog(name,age){
				this.name=name;
				this.age=age;
				this.sayName=fun;
			}
			function fun(){             /*全局区域中，不安全*/
					console.log(this.name);
			};
			var dog2=new Dog("桔",4);
			console.log(dog2);
		/*利用原型对象改成（2）【推荐使用】*/
			function Dog(name,age){
				this.name=name;
				this.age=age;
			}
			Dog.prototype.sayName=function(){             
					console.log(this.name);
			};
			var dog3=new Dog("青",5);
			dog3.sayName();
		/*检查对象自身是否有sayName*/
			console.log(dog3.hasOwnProperty("sayName"));
		/*检查原型的原型中是否有hasOwnProperty*/
			console.log(dog3.__proto__.__proto__.hasOwnProperty("hasOwnProperty"));
			
			
		/*判断是否是某个类的实例*/
			console.log(per1 instanceof Person);
			console.log(dog instanceof Dog);
		</script>
	</head>
	<body>
	</body>
</html>
